package com.pro.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author 谭金诚
 * @Description TODO
 * @Date 2022/1/22 12:20
 * @Version 1.0
 */
public class ContextHolderUtils {

    //获取HttpServletRequest对象
    public static HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    //获取HttpSession对象
    public static HttpSession getSession() {
        HttpSession session = getRequest().getSession();
        return session;
    }
}
